package service

import (
	"context"
	"errors"
	__ "service/basic/proto"
	"service/handler/model"
	"strconv"
)

type Server struct {
	__.UnimplementedStreamGreeterServer
}

// 课程添加
func (s *Server) ClassCreate(_ context.Context, in *__.ClassCreateReq) (*__.ClassCreateResp, error) {
	class := model.Class{
		Name:     in.Name,
		Info:     in.Info,
		Price:    float64(in.Price),
		DisPrice: float64(in.DisPrice),
	}
	err := class.Create()
	if err != nil {
		return nil, errors.New("课程添加失败")
	}
	return &__.ClassCreateResp{
		Id: strconv.Itoa(int(class.Id)),
	}, nil
}
